package onki.tests.pageObjects;

import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import org.openqa.selenium.support.*;
import org.openqa.selenium.*;

public class OnkiStatisticsPageObject {
  
  @FindBy(id = "statistics")
  private WebElement conceptCountTable;

  public OnkiStatisticsPageObject() {

  }

  public HashMap<String, ArrayList<Integer>> getConceptCountList() {
    HashMap<String, ArrayList<Integer>> countMap = new HashMap();
    List<WebElement> tableRows = conceptCountTable.findElements(By.xpath(".//tr"));
    System.out.println(tableRows);
    boolean first = true;
    for (WebElement row : tableRows) {
      ArrayList<Integer> conceptCounts = new ArrayList();
      List<WebElement> tableDivs = row.findElements(By.xpath(".//td"));
      String lang = new String(); 
      for (WebElement td : tableDivs) {
        if (!td.getText().matches("\\d+")) {
          lang = td.getText();          
        } else {
          int count = Integer.parseInt(td.getText());
          conceptCounts.add(count);
        }
      } 
      countMap.put(lang, conceptCounts);
    }
    return countMap;
  }

}
